/*
 * InGameState.cpp
 *
 *  Created on: 30.11.2009
 *      Author: Sergej Schmidt
 */

#include "InGameState.h"

using namespace Ogre;

InGameState InGameState::m_pInGameState;

void InGameState::enter()
{
	// стандартная процедура
	m_pRoot = Root::getSingletonPtr();
	m_pRenderWindow = m_pRoot->getAutoCreatedWindow();
	m_pSceneMgr = GameManager::getSingleton().getSceneManager();
    m_pCamera = GameManager::getSingleton().getCamera();
    m_pViewport = GameManager::getSingleton().getViewport();

    m_pTheGame = new TheGame();
	// TODO загрузка TheGame
}

void InGameState::exit()
{
	if( m_pTheGame )
	{
		delete m_pTheGame;
		m_pTheGame = 0;
	}
}

void InGameState::pause()
{
	// TODO InGameState::Pause
}

void InGameState::resume()
{
	// TODO InGameState::resume()
}

void InGameState::keyPressed(const OIS::KeyEvent& e)
{
	if(m_pGui) m_pGui->injectKeyPress( MyGUI::KeyCode::Enum(e.key), e.text );
}

void InGameState::keyReleased(const OIS::KeyEvent& e)
{
	if(m_pGui) m_pGui->injectKeyRelease( MyGUI::KeyCode::Enum(e.key) );
}

void InGameState::mouseMoved( const OIS::MouseEvent& e )
{
	if(m_pGui) m_pGui->injectMouseMove( e.state.X.abs, e.state.Y.abs, e.state.Z.abs );
}

void InGameState::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id )
{
	if(m_pGui) m_pGui->injectMousePress( e.state.X.abs, e.state.Y.abs, MyGUI::MouseButton::Enum(id) );
}

void InGameState::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id )
{
	if(m_pGui) m_pGui->injectMouseRelease( e.state.X.abs, e.state.Y.abs, MyGUI::MouseButton::Enum(id) );
}

bool InGameState::frameStarted(const Ogre::FrameEvent& evt)
{
	if(m_pGui) m_pGui->injectFrameEntered( evt.timeSinceLastFrame );
	return true;
}

bool InGameState::frameEnded(const Ogre::FrameEvent& evt)
{
	if(m_bExitGame)
		return false;
	return true;
}
